{{extend 'layout.html'}}

<script type="text/javascript">
     $(document).ready(function(){
         $("#dialog-confirm").dialog({ autoOpen: false });         
     });

    function delete_user(usr_id) {    
          $("#dialog-confirm").dialog("open");
          $("#dialog-confirm").dialog({
              autoOpen: false,
              modal:true,
              buttons : {
                "Yes" : function() {              
                    $(this).dialog("close");
                    // get call:
                    window.location.href='delete_user/' + usr_id;
                    return                                                                                  
                },
                "No" : function() {
                    $(this).dialog("close");
                }
            }
        });       
     }
</script>
<br/>
<br/>
<div id="dialog-confirm" title="Confirm">
    {{=T('Are you sure you want to delete the user?')}} 
</div>

<table style="border-collapse: separate; border-spacing: 5px">
    <thead>
        <tr>
            <th style="width: 150px">
                {{=T('First Name')}}
            </th>
            <th style="width: 150px">
                {{=T('Last Name')}}
            </th>
            <th style="width: 150px">
                {{=T('email')}}
            </th>
            <th style="width: 60px">
                {{=T('Admin')}}
            </th>
            <th></th>
            <th></th>
        </tr>
    </thead>
    
    {{for i, usr in enumerate(users):}}
        {{=TR(
            TD(usr.auth_user.first_name),
            TD(usr.auth_user.last_name),
            TD(usr.auth_user.email),
            TD('Y' if usr.auth_group.role=='admin' else '', _style='text-align:center;'),
            TD(
                    A(
                    IMG(_src=URL( request.application , 'static/images', 'application_edit.png')), _href=URL('users/%s' %usr.auth_user.id))),
            TD(A(
                    IMG(_src=URL( request.application , 'static/images', 'cancel.png')), _href='#' , _onclick='delete_user(\'%s\')' %usr.auth_user.id)),
            _class='even' if not i%2 else 'odd'
        )}}
    {{pass}}
    
</table>
<br/>
<form method="post" enctype="multipart/form-data" action="">
    <table>
        <tbody>         
            <tr id="auth_user_first_name__row">
                <td class="w2p_fl"><label id="auth_user_first_name__label" for="auth_user_first_name">First name: </label></td>
                <td class="w2p_fw"><input type="text" value="{{=user.first_name if user else '' }}" name="first_name" id="auth_user_first_name" class="string"></td>
                <td class="w2p_fc"></td>
            </tr>
            <tr id="auth_user_last_name__row">
                <td class="w2p_fl"><label id="auth_user_last_name__label" for="auth_user_last_name">Last name: </label></td>
                <td class="w2p_fw"><input value="{{=user.last_name if user else '' }}" type="text" name="last_name" id="auth_user_last_name" class="string"></td>
                <td class="w2p_fc"></td>
            </tr>
            <tr id="auth_user_email__row">
                <td class="w2p_fl"><label id="auth_user_email__label" for="auth_user_email">E-mail: </label></td>
                <td class="w2p_fw"><input value="{{=user.email if user else '' }}" type="text" name="email" id="auth_user_email" class="string"></td>
                <td class="w2p_fc"></td>
            </tr>
            <tr id="auth_user_password__row"><td class="w2p_fl"><label id="auth_user_password__label" for="auth_user_password">Password: </label></td>
                <td class="w2p_fw"><input type="password" value="" name="password" id="auth_user_password" class="password"></td>
                <td class="w2p_fc"></td>
            </tr>
            <tr id="auth_user_admin_row">
                <td class="w2p_fl"><label id="auth_user_admin__label" for="auth_user_admin">Admin: </label></td>
                <td class="w2p_fw"><input type="checkbox" name="admin" value='y' id="auth_user_admin" class="admin" {{='checked' if is_admin else ''}}></td>
                <td class="w2p_fc"></td>
            </tr>
            <tr id="submit_record__row">
                <td class="w2p_fl"></td>
                <td class="w2p_fw"><input type="submit" value="Submit"></td>
                <td class="w2p_fc"></td>
            </tr>
        </tbody>
    </table>
    <div class="hidden" style="display: none;">
        <input type="hidden" value="{{=user.id if user else '' }}"name="id">
        <input type="hidden" value="auth_user" name="_formname">
    </div>
</form>
